var img = null
var data = null
var scores = null
var counts = 0
    // console.log("ssad")
$.getJSON("JSON/yangzhengma.json", function(e) {
    data = e
    console.log(data)
})

function addspicture(e) {

    var htmls = ""

    var suiji = Math.floor(Math.random() * 4)
    console.log("随机数" + suiji)

    htmls += `<img src="yanzheng/${data[suiji].img}" style="width: 100%;height: 100%;"/>`

    scores = data[suiji].number
    console.log("1111:" + scores)
    document.getElementById("imgssss").innerHTML = htmls
}

window.onload = function() {
    addspicture(0)
    var btn = document.getElementById('btn')
    var dianji = document.getElementById("imgssss")
        // console.log("user:" + user + "111")
    dianji.onclick = function() {
        console.log("一点击")
        var htmls = ""

        var suiji = Math.floor(Math.random() * 4)
        console.log("随机数" + suiji)

        htmls += `<img src="yanzheng/${data[suiji].img}" style="width: 100%;height: 100%;"/>`

        scores = data[suiji].number
        console.log("1111:" + scores)
        document.getElementById("imgssss").innerHTML = htmls
    }
    btn.onclick = function() {
        console.log(counts)
        counts = 0
        var user = $('#user').val(); //获取值
        var psd = $('#psd').val();
        var score = $('#score').val();
        // var user = document.getElementById('user')
        // console.log(user)

        for (var s = 0; s < localStorage.length; s++) {
            if (localStorage.key(s) == user) { counts++ }
        }

        if (counts != 0) {
            console.log("1111")
            confirm("用户名已存在")

        } else if (user == '') {
            alert('请输入账号')

        } else {
            if (psd == '') {
                alert('请输入密码')

            } else {
                if (score == scores) {
                    for (var i = 0; i < localStorage.length; i++) {
                        console.log(
                            'localStorage里存储的第' +
                            i +
                            '条数据的名字为：' +
                            localStorage.key(i) +
                            ',值为：' +
                            localStorage.getItem(localStorage.key(i)));
                    }
                    alert('注册成功')
                    localStorage.setItem(user, psd)
                    window.location = 'z-login.html'

                } else {
                    alert('验证码不正确')

                }
            }
        }
    }

}